﻿using System.Windows;
using System;

namespace ZOIL.Framework.Presentation
{
    /// <summary>
    /// Zoom Modifier for borders.
    /// </summary>
    public class ThicknessModifier : ZoomModifier
    {
        #region dp

        /// <summary>
        /// 
        /// </summary>
        public static readonly DependencyProperty ModifierProperty = DependencyProperty.Register("Modifier", typeof(double), typeof(ThicknessModifier), new PropertyMetadata(0.0));

        /// <summary>
        /// 
        /// </summary>
        public double Modifier
        {
            get { return (double)this.GetValue(ModifierProperty); }
            set { this.SetValue(ModifierProperty, value); }
        }

        #endregion

        #region overrides

        /// <summary>
        /// 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="zoom"></param>
        public override void Update(DependencyObject source, double zoom)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            base.Update(source, zoom);

            double modifier = Interpolate(zoom, this.Modifier);
            if (OriginalValue.GetType() == typeof(double))
            {
                source.SetValue(this.Property, (double)OriginalValue * modifier);
                return;
            }
            Thickness originalThickness = (Thickness)OriginalValue;
            Thickness newThickness = new Thickness(
                originalThickness.Left * modifier,
                originalThickness.Top * modifier,
                originalThickness.Right * modifier,
                originalThickness.Bottom * modifier);

            source.SetValue(this.Property, newThickness);
        }

        #endregion 
    }
}
